// 读取
const fs = require('fs')
// 压缩工具
const geobuf = require('geobuf')
const Pbf = require('pbf')

function zipGeoJson(pathName) {
  var data = fs.readFileSync('./' + pathName + '.json', {
    encoding: 'utf8',
  })
  let json = JSON.parse(data)
  let buffer = geobuf.encode(json, new Pbf())
  // // 写入
  fs.writeFile('./' + pathName + '.bpf', buffer, function (error) {
    if (error) {
      console.info('geobuf error')
    } else {
      console.info('geobuf ok')
    }
  })
}
zipGeoJson('changjiang_huanghe_huaihe')
